<template>
  <div class="step">
    <div class="content">
      <div class="pic">
        <img src="@/assets/success.png" alt="">
      </div>
      <h2>设置成功</h2>
      <div class="next" @click="login">去登陆 ({{ time }}s)</div>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      time: 20,
      timer: null
    }
  },
  created () {
    this.countDown()
  },
  watch: {
    time: {
      handler: function (val) {
        // console.log(val)
        if (val === 0) {
          this.$router.push('/login')
          clearInterval(this.timer)
        }
      },
      deep: true
    }
  },
  methods: {
    login () {
      this.$router.push('/login')
      clearInterval(this.timer)
    },
    countDown () {
      const that = this
      //   const timer = setInterval(() => {
      //     that.time--
      //   }, 1000)
      this.timer = setInterval(() => {
        that.time--
      }, 1000)
    }
  }
}
</script>

<style lang="scss" scoped>
.step {
  overflow: hidden;
  text-align: center;
  .pic {
    width: 64px;
    height: 64px;
    margin-top: 128px;
    display: inline-block;
    img{
      width: 100%;
    }

  }
  h2 {
    margin-top: 25px;
    font-size: 20px;
    font-weight: 600;
    color: #1b1f35;
    margin-bottom: 60px;
  }
  .next {
    display: inline-block;
    width: 360px;
    height: 44px;
    opacity: 1;
    background: #304eec;
    border-radius: 4px;
    line-height: 44px;
    color: #ffffff;
    text-align: center;
  }
}
</style>
